package com.itheima.homework;

import java.util.*;

/**
 * @author shanh
 * 双色球案例
 * 1.投注是从红色球号码中选择6个号码(不能重复)，从蓝色球号码中选择1个号码，组合为一注投注号码的投注
 * 2.红色球号码为[1-33],蓝色球号码为[1-16]
 * 3.开奖号码和购彩者号码均随机生成,红球按照从小到大的顺序进行排列,最后额外加入蓝色球
 * 1 2 3 4 5 6 + 1
 * 注意:蓝色球不参与整体的顺序
 * 4.中奖规则如下:
 * 一等奖: 红球6 + 蓝球1
 * 二等奖: 红球6
 * 三等奖: 红球5 + 蓝球1
 * 四等奖: 红球5 或 (红球4 + 蓝球1)
 * 五等奖: 红球4 或 (红球3 + 蓝球1)
 * 六等奖: (红球2 + 蓝球1) 或 (红球1 + 蓝球1) 或 蓝球1
 */
public class BichromaticSphere {
    public static void main(String[] args) {
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        //定义红球范围
        ArrayList<Integer> redIntegers = getRedIntegers(r);
        //定义蓝球范围
        ArrayList<Integer> blueIntegers = getBlueIntegers(r);

        System.out.println("回复1购买");
        int choice = sc.nextInt();

        if (choice == 1) {
            int[] count ={0,0,0,0,0,0,0};
            ballResult(r, redIntegers, blueIntegers, choice,count);
        }
        if (choice == 1456247612) {
            System.out.println("请输入购买次数");
            int payCount = sc.nextInt();
            for (int i = 0; i < payCount; i++) {
                int[] count ={0,0,0,0,0,0,0,0};
              int[] result =  ballResult(r, redIntegers, blueIntegers, choice,count);
                for (int j = 0; j < result.length; j++) {
                    System.out.println(j);
                }
              //  System.out.println("您购买了" + countPay + "次彩票" + " 中了" + count1 + "次一等奖 " + count2 + "次二等奖 " + count3 + "次三等奖 " + count4 + "次四等奖 " + count5 + "次五等奖 " + count6 + "次六等奖 " + countNone + "次未中奖");

            }

               // System.out.println("您购买了" + countPay + "次彩票" + " 中了" + count1 + "次一等奖 " + count2 + "次二等奖 " + count3 + "次三等奖 " + count4 + "次四等奖 " + count5 + "次五等奖 " + count6 + "次六等奖 " + countNone + "次未中奖");

        }
    }

    private static int[] ballResult(Random r, ArrayList<Integer> redIntegers, ArrayList<Integer> blueIntegers, int choice, int[] count) {
        //生成系统随机红球
        ArrayList<Integer> getIntegers = new ArrayList<>();
        for (int i = 0; i < 6; ) {
            //返回redIntegers的随机索引以返回redIntegers的随机元素
            int redTemp = redIntegers.get(r.nextInt(redIntegers.size()));
            if (!getIntegers.contains(redTemp) ){
                getIntegers.add(redTemp);
                i++;
            }

        }
        Collections.sort(getIntegers);
        System.out.println("本次系统红球是" + getIntegers);

        //生成系统随机蓝球球
        ArrayList<Integer> getbIntegers = new ArrayList<>();
        for (int i = 0; i < 1; ) {
            //返回redIntegers的随机索引以返回redIntegers的随机元素
            int blueTemp =blueIntegers.get(r.nextInt(blueIntegers.size()));
            if (!getbIntegers.contains(blueTemp)) {
                getbIntegers.add(blueTemp);
                i++;
            }

        }
        System.out.println("本次系统蓝球是" + getbIntegers);

        System.out.println("================================");

        //生成用户随机红球
        ArrayList<Integer> payIntegers = new ArrayList<>();
        for (int i = 0; i < 6; ) {
            //返回redIntegers的随机索引以返回redIntegers的随机元素
            int  payRtemp = redIntegers.get(r.nextInt(redIntegers.size()));
            if (!payIntegers.contains(payRtemp)) {
                payIntegers.add(payRtemp);
                i++;
            }

        }
        //测试redIntegers是否改变,未变
        // System.out.println(redIntegers);
        Collections.sort(payIntegers);
        System.out.println("本次您的红球是" + payIntegers);

        //生成用户随机蓝球
        ArrayList<Integer> paybIntegers = new ArrayList<>();
        for (int i = 0; i < 1; ) {
            //返回blueIntegers的随机索引以返回blueIntegers的随机元素
            int payBtemp = blueIntegers.get(r.nextInt(blueIntegers.size()));
            if (!paybIntegers.contains(payBtemp)) {
                paybIntegers.add(payBtemp);
                i++;
            }

        }
        System.out.println("本次您的蓝球是" + paybIntegers);

        System.out.println("================================");

        //定义红球相同次数
        int redCount = getRedCount(getIntegers, payIntegers);
        //定义蓝球相同次数
        int blueCount = getBlueCount(getbIntegers, paybIntegers);
        //中奖次数

        //中奖判断
        if (redCount == 6 && blueCount == 1) {
            System.out.println("恭喜您中了一等奖!");
            count[0]++;
        } else if (redCount == 6 && blueCount != 1) {
            System.out.println("恭喜您中了二等奖!");
            count[1]++;
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜您中了三等奖!");
            count[2]++;
        } else if ((redCount == 5 && blueCount != 1) || (redCount == 4 && blueCount == 1)) {
            System.out.println("恭喜您中了四等奖!");
            count[3]++;
        } else if ((redCount == 4 && blueCount != 1) || (redCount == 3 && blueCount == 1)) {
            System.out.println("恭喜您中了五等奖!");
            count[4]++;
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)) {
            System.out.println("恭喜您中了六等奖!");
            count[5]++;
        } else {
            System.out.println("sorry,小帅哥再来一次吧");
            count[6]++;
        }
        count[7]++;

        return count;
      //  System.out.println("您购买了" + countPay + "次彩票" + " 中了" + count1 + "次一等奖 " + count2 + "次二等奖 " + count3 + "次三等奖 " + count4 + "次四等奖 " + count5 + "次五等奖 " + count6 + "次六等奖 " + countNone + "次未中奖");

        // return count1;



    }

    private static int getBlueCount(ArrayList<Integer> getbIntegers, ArrayList<Integer> paybIntegers) {
        int blueCount = 0;
        for (int i = 0; i < 1; i++) {
            if (paybIntegers.contains(getbIntegers.get(i))) {
                blueCount = blueCount + 1;
            }
        }
        System.out.println("蓝相同的个数为:" + blueCount);

        //int redCount =6 - (payIntegers.removeAll(redIntegers))
        return blueCount;
    }

    private static ArrayList<Integer> getBlueIntegers(Random r) {
        //定义蓝球范围
        ArrayList<Integer> blueIntegers = new ArrayList<>();
        for (int i = 0; i < 16; ) {
            int blueScore = r.nextInt(16) + 1;
            if (!blueIntegers.contains(blueScore)) {
                blueIntegers.add(blueScore);
                i++;
            }
        }
        // Collections.sort(blueIntegers);
        System.out.println(blueIntegers);
        // System.out.println(redIntegers.size());
        return blueIntegers;
    }

    private static ArrayList<Integer> getRedIntegers(Random r) {
        //定义红球范围
        ArrayList<Integer> redIntegers = new ArrayList<>();
        for (int i = 0; i < 33; ) {
            int redScore = r.nextInt(33) + 1;
            if (!redIntegers.contains(redScore)) {
                redIntegers.add(redScore);
                i++;
            }
        }
        //检验范围是否正确
        // Collections.sort(redIntegers);
        System.out.println(redIntegers);
        return redIntegers;
    }

    private static int getRedCount(ArrayList<Integer> getIntegers, ArrayList<Integer> payIntegers) {
        int redCount = 0;
        for (int i = 0; i < 6; i++) {
            if (payIntegers.contains(getIntegers.get(i))) {
                redCount = redCount + 1;
            }
        }
        System.out.println("红球相同的个数为:" + redCount);
        return redCount;
    }
}
